import Dayjs from "dayjs";

export const mouthMap = {
  Jan: "1月",
  Feb: "2月",
  Mar: "3月",
  Apr: "4月",
  May: "5月",
  Jun: "6月",
  Jul: "7月",
  Aug: "8月",
  Sep: "9月",
  Oct: "10月",
  Nov: "11月",
  Dec: "12月",
};

export function getDayWeek(date) {
  var l = ["日", "一", "二", "三", "四", "五", "六"];
  var d = new Date(date).getDay();
  return "周" + l[d];
}
export function getGanttConfigByZoomValue(gantt, value) {
  const yearFormat = (date) => {
    return `${Dayjs(date).format("YYYY") + "年"}`;
  };
  if (value === "week") {
    const dayFormat = function (date) {
      const weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
      return Dayjs(date).format("MM-DD") + " " + weeks[Dayjs(date).day()];
    };

    return [
      { unit: "year", step: 1, format: yearFormat },
      { unit: "day", step: 1, format: dayFormat },
    ];
  } else if (value === "month") {
    const monthFormat = (date) => {
      return Dayjs(date).month() + 1 + "月" + Dayjs(date).date() + "号";
    };
    return [
      { unit: "year", step: 1, format: yearFormat },
      { unit: "day", step: 3, format: monthFormat },
    ];
  } else if (value === "quarter") {
    const FormatQuarter = (date) => {
      console.log(Dayjs(date).month() + 1 + "月");
      return Dayjs(date).year() + "年" + (Dayjs(date).month() + 1) + "月";
    };
    const dayFormat = (date) => {
      const endDate = gantt.date.add(
        gantt.date.add(date, 1, "week"),
        -1,
        "day"
      );
      // 处理一下月份
      return Dayjs(date).date() + "号" + "-" + Dayjs(endDate).date() + "号";
    };
    return [
      { unit: "month", step: 1, format: FormatQuarter },
      { unit: "week", step: 1, format: dayFormat },
    ];
  } else if (value === "year") {
    const monthFormat = (date) => {
      return Dayjs(date).month() + 1 + "月";
    };
    return [
      { unit: "year", step: 1, format: yearFormat },
      { unit: "month", step: 1, format: monthFormat },
    ];
  }
}
